home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c,comp.lang.c++
- Path: bath.ac.uk!bsmail!talisker!nathan
- From: nathan@pact.srf.ac.uk (Nathan Sidwell)
- Subject: Re: Poor floating point code in BC++
- Message-ID: <DKLtwv.MME@uns.bris.ac.uk>
- Followup-To: comp.lang.c,comp.lang.c++
- Sender: usenet@uns.bris.ac.uk (Usenet news owner)
- Nntp-Posting-Host: talisker.pact.srf.ac.uk
- Organization: Inmos
- X-Newsreader: TIN [version 1.2 PL2]
- References: <4c9sja$gke$1@mhafc.production.compuserve.com>
- Date: Wed, 3 Jan 1996 12:12:30 GMT
-
- Dave Hand (70621.3624@CompuServe.COM) wrote:
- : BC++ 4.51 seems to generate very poor floating point code. I would be
- : interested to know how well other compilers do on the following
- : examples. These were compiled using options: i486 CPU, fast floating
- : point, optimize for speed, large memory model.
-
- :[float to int conversion]
-
- : where FTOL@ is a very long function for what is does:
-
- : push bp
- : mov bp,sp
- : sub sp,000A
- : fnstcw word ptr[bp-02]
- : fwait
- : mov al,[bp-01]
- : or byte ptr[bp-01],0C
- : fldcw word ptr[bp-02]
- : fistp qword ptr [bp-0A] <<-- here is the meat of it.
- : mov [bp-01],al
- : fldcw word ptr[bp-02]
- : mov ax,[bp-0A]
- : mov dx,[bp-08]
- : mov sp,bp
- : pop bp
- : retf
-
- The preamble is saving the rounding mode and setting it to round to zero
- (I think, I've not got a 387 manual infront of me) and the postamble
- is restoring the previous rounding mode.
-
- It has to be done this way, because
- a)float to int conversion is defined to remove the 'fractional part'. On
- a sign magnitude system (which 387 is), this is the same as round to zero.
- b)there is a function to set the rounding mode for all operations (I forget
- the name), thus the rounding mode is unknown and must be preserved by the
- conversion.
-
- Unfortuneately the compiler cannot tell when the rounding mode is already
- correct, it's a problem with the 387 instruction set not having instructions
- which explicitly state the rounding mode to use.
-
- nathan
- --
- Nathan Sidwell Holder of the Xmris home page
- Chameleon Architecture Group at SGS-Thomson, formerly Inmos
- http://www.pact.srf.ac.uk/~nathan/ Tel 0117 9707182
- nathan@inmos.co.uk or nathan@bristol.st.com or nathan@pact.srf.ac.uk
- Having problems? try http://www.pact.srf.ac.uk/~nathan/problems/
-